var events = require('events');
var Emitter = events.EventEmitter;
function Dog(name,energy){
    Emitter.call(this);
    this.name = name;
    this.energy = energy;
    var intervalID=setInterval(() => {
        if(this.energy>=0){
            this.emit('bark')
            this.energy--;
        }else{
            clearInterval(intervalID)
        }
    }, 1000);
}
// Dog.prototype = Emitter.prototype;
//避免直接将原型赋值会把原函数模型完全覆盖的问题
for(var i in Emitter.prototype){
    Dog.prototype[i] = Emitter.prototype[i]
}
/*Dog.prototype.bark = function(){
    console.log(this.name+" barked! energy: "+this.energy)
    this.energy--;
}*/
module.exports = Dog;